<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <link rel="stylesheet" href="../css/myequipment.css">
    <link rel="stylesheet" href="../css/deviceinfor.css">
    <script src="../js/jquery.min.js"></script>
    <script src="../js/fontzize.js"></script>
    <script src="../js/vue.min.js"></script>
    <script src="../js/jsonAjax.js"></script>

</head>
<body>
<div id="app">
    <header>
        <nav @click="goback"><img src="../imgs/arrow_left.png"></nav>
        <nav>设备信息</nav>
        <nav></nav>
    </header>
    <section>
        <dl v-show="indexof('s001')">
            <dd >设备名称</dd>
            <dd @click="popups"><span v-html="device_name"></span><img src="../imgs/arrow_right.png" v-if="role==1"></dd>
        </dl>
        <dl v-show="indexof('8001')">
            <dd>设备类型</dd>
            <dd> <span v-html="getdata.device_name"></span> </dd>
        </dl>
        <dl v-show="indexof('s002')">
            <dd>设备序列号</dd>
            <dd> <span v-html="getdata.device_sn"></span> </dd>
        </dl>
        <dl v-show="indexof('8002')">
            <dd>固件版本</dd>
            <dd> <span v-html="getdata.firmware_version"></span> </dd>
        </dl>
        <dl v-show="indexof('101b')">
            <dd>药盘总格数</dd>
            <dd> <span v-html="getdata.device_ceil_amount"></span></dd>
        </dl>

    </section>
    <aside>
        <div class="popup" v-if="pupo&&role==1" >
            <div class="editor_box">
                <div class="editor">设备名称<br>
                    <input type="text" :placeholder ="getdata.my_device_name" v-model="device_name">
                    <div class="determination" @click="determine">确定</div>
                    <div class="cancelled" @click="cancel">取消</div>
                </div>
            </div>
        </div>
    </aside>
</div>
<script type="text/javascript">
    var rawdata;
    Vue.config.debug = true;
    app = new Vue({
        el: "#app",
        data: {
            getdata:{},
            pupo:false,
            device_name:'',
            role:0,
            showdash:[]
        },
        watch:{
            'device_name':function (newVal, oldVal) {
                console.log(oldVal);
                if(newVal.length<3){
                    return oldVal;
                }
            }

        },
        mounted: function () {
            var _this = this;
            //获取外部链接参数
            function GetQueryString(name) {
                var reg = new RegExp("(^|&)" + name + "([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null)return unescape(r[2]);
                return null;
            }
            var myurl = GetQueryString("device_id");
            if (myurl != null && myurl.toString().length > 1) {
                _this.device_id =Number(GetQueryString("device_id").substr(1));
            }
            else {

            }
            var role = GetQueryString("role");
            if (role != null && role.toString().length > 1) {
                _this.role =Number(GetQueryString("role").substr(1));
            }
            else {

            }

            var token = GetQueryString("token");
            if (token != null && role.toString().length > 1) {
                _this.token =GetQueryString("token").substr(1);

            }
            else {
                //window.location.href =golinks("");

            }
            var uid = GetQueryString("uid");
            if (uid != null && role.toString().length > 1) {
                _this.uid = Number(GetQueryString("uid").substr(1));

            }
            else {
                //window.location.href =golinks("");

            }
            _this.dtcs(_this.device_id)
            //接口名称 13 获取设备基本信息√
                jsonAjax("/Home/Device/get_device_info",
                    {access_token:_this.token,device_id: _this.device_id, uid: _this.uid}
                ).done(function (data) {
                    if(data.code==40002){
                        window.location.href=golinks('weixinsq.html')
                    }
                    else if(data.code==40010){
                        window.location.href=golinks('weixinsq.html')
                    }
                    else if(data.code ==0){
                        rawdata=data.data.my_device_name;
                        _this.device_name=data.data.my_device_name;
                        _this.getdata=data.data;

                    }


                })
                    .fail(function () {
                        console.log("error");
                    });



        },
        methods: {
            dtcs:function (e) {
                var _this=this;
                jsonAjax('/Home/Device/dynamic_device_params',
                    {access_token:this.token,device_id:e, uid:this.uid}
                ).done(function (data) {
                    console.log(data.data)
                    for(var i in data.data){
                        _this.showdash.push(data.data[i].tag)
                    }

                });
            },
            indexof:function (item) {
                if(this.showdash.indexOf(item)==-1){
                    return false;
                }else {
                    return true;
                }
            },
            popups:function () {
                this.pupo=true;
            },
            determine:function () {
                var _this=this;
                if(_this.device_name<1){
                    alert("设备名称不能为空！");
                    _this.device_name=rawdata;
                    return false;

                };
                jsonAjax("/Home/Device/edit_my_device_name",{
                    access_token:_this.token,
                    device_id: _this.device_id,
                    my_device_name:_this.device_name,
                    uid: _this.uid
                }).done(function (data) {
                    if(data.code==40002){
                        window.location.href=golinks('weixinsq.html')
                    }
                    else if(data.code==40010){
                        window.location.href=golinks('weixinsq.html')
                    }
                    else if(data.code ==0){
                        _this.pupo=false;

                    }
                })
                    .fail(function () {
                        console.log("error");
                    });
            },

            cancel:function () {
                if(this.device_name<1){
                    this.device_name=rawdata;
                    return false;
                };
                this.pupo=false;
            },
            goback:function () {
                window.location.href= golinks("dmanagement/devicedetails.html?token="+this.token+"&uid="+this.uid+"&device_id="+this.device_id+"&role="+this.role+"&off=1");
            },

            configuration:function () {

            }

        }

    });

</script>
</body>

</html>

